﻿using System;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;

using gKodes.Drawing;
using gKodes.Collections;

namespace gKodes.Windows.Forms.Internals
{
    public class OffsetSegment : HexView.PageSegment
    {
        private long hCCount;

        public override string Name
        {
            get { return "Offset"; }
        }

        public string FormatString { get; set; }

        public override void ResizeTo(Size size)
        {
            size.Width = this.CellSize.Width + this.CellProperties.Padding.Horizontal;
            this.FormatString = "X" + base.CellProperties.Size.Width;
            base.ResizeTo(size);
        }

        public override void RenderSegment(Rectangle clip)
        {
            HexView.PageSegment mHVPainter = (HexView.PageSegment)this.FindSegment("Hex");
            this.hCCount = mHVPainter.Columns;
            this.DrawForeHelper(0, 
                ((this.OffsetStates.End - this.OffsetStates.Start)/ this.DrawnOn.Columns),
                this.DrawnOn.PaintSchemes[0].Foreground);//this.Size - 1,
        }

        protected override string HelperSource(int x, int y, long i)
        {
            return ((int)((i * this.hCCount) + this.OffsetStates.Start))
                            .ToString(this.FormatString, Thread.CurrentThread.CurrentCulture);
        }
    }
}
